package demo2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-11-01
 * Time: 17:12
 */
public class Demo {
    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Object locker2 = new Object();

        Thread t1 = new Thread(() -> {
            synchronized (locker1) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (locker2){
                    System.out.println("t1线程两个锁都获取到了");
                }
            }

            System.out.println("t1 结束");
        });
        Thread t2 = new Thread(() -> {
            synchronized (locker1) {

                synchronized (locker2){
                    System.out.println("t2线程两个锁都获取到了");
                }
            }

            System.out.println("t2 结束");
        });

        t1.join();
        t2.join();

        t1.start();
        t2.start();
    }
}
